package cn.com.roy.thread.t4_2_2.readwritelockbegine2;

import java.util.concurrent.locks.ReentrantReadWriteLock;

public class Service {
    private ReentrantReadWriteLock lock = new ReentrantReadWriteLock();

    public void read() {
        try {
            lock.writeLock().lock();
            System.out.println("Thread " + Thread.currentThread().getName()
                    + "获得写锁 " + System.currentTimeMillis()
            );
            Thread.sleep(5000);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            lock.writeLock().unlock();
        }

    }
}
